﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace System.Web.Mvc
{
    public static class DropDownListHelper
    {
        public static MvcHtmlString DropDownListForMonth(this HtmlHelper htmlHelper, string propertyName, int? value = null)
        {
            int[] months = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(months), "----");
            }
            else
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(months,value.Value));
            }
        }
        public static MvcHtmlString DropDownListForYear(this HtmlHelper htmlHelper, string propertyName, int? value = null)
        {
            List<int> years = new List<int>();
            {
                for (int i = 10; i > -101; i--)
                {
                    years.Add(DateTime.Now.Year + i);
                }
            }
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(years), "----");
            }
            else
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(years, value.Value));
            }
        }
        public static MvcHtmlString DropDownListForMonth(this HtmlHelper htmlHelper, int index, string propertyName, int? value = null)
        {
            int[] months = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(months), "----");
            }
            else
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(months,value.Value ));
            }
        }
        public static MvcHtmlString DropDownListForYear(this HtmlHelper htmlHelper, int index, string propertyName, int? value = null)
        {
            List<int> years = new List<int>();
            {
                for (int i = 10; i > -101; i--)
                {
                    years.Add(DateTime.Now.Year + i);
                }
            }
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(years), "----");
            }
            else
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(years,value.Value));
            }
        }
        public static MvcHtmlString DropDownListForSex(this HtmlHelper htmlHelper, int index, string propertyName, bool? value = null)
        {
            List<KeyValuePair<string, bool>> sexs = new List<KeyValuePair<string, bool>>();
            sexs.Add(new KeyValuePair<string, bool>("Nam", true));
            sexs.Add(new KeyValuePair<string, bool>("Nữ", false));
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(sexs, "Value", "Key"), "----");
            }
            else
            {

                return Html.SelectExtensions.DropDownList(htmlHelper, string.Format("[{0}].", index.ToString()) + propertyName, new SelectList(sexs, "Value", "Key",value.Value));
                
            }
        }
        public static MvcHtmlString DropDownListForSex(this HtmlHelper htmlHelper, string propertyName, bool? value = null)
        {
            List<KeyValuePair<string, bool>> sexs = new List<KeyValuePair<string, bool>>();
            sexs.Add(new KeyValuePair<string, bool>("Nam", true));
            sexs.Add(new KeyValuePair<string, bool>("Nữ", false));
            if (value == null)
            {
                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(sexs, "Value", "Key"), "----");
            }
            else
            {

                return Html.SelectExtensions.DropDownList(htmlHelper, propertyName, new SelectList(sexs, "Value", "Key", value.Value));
            }
        }
    }
}